<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:py="http://genshi.edgewall.org/">
  <xi:include href="discussion-macros.html"/>
  <xi:include href="layout.html"/>
  <head>
    <title>Add Topic</title>
  </head>

  <?python
    from trac.wiki.formatter import format_to_html
    from trac.util.datefmt import format_datetime, pretty_timedelta
  ?>

  <body>
    <xi:include href="discussion-header.html"/>

    <div id="content" class="discussion">
      <h1 class="subpage_title">Add Topic</h1>
      <div id="${discussion.mode}" class="${discussion.mode}">
        <div py:if="req.args.preview" class="message-list">
          <div class="topic">
            <div class="header">
              <div class="subject">
                ${req.args.subject or '&nbsp;'}
              </div>
              <div class="body">
                ${req.args.body and format_to_html(discussion.env, context, req.args.body) or '&nbsp;'}
              </div>
              <div class="footer">
                <div class="author">
                  ${req.args.author}
                </div>
                <div class="time">
                  ${format_datetime(discussion.time)} (${pretty_timedelta(discussion.time)} ago)
                </div>
              </div>
            </div>
          </div>
        </div>

        <form class="add_form" method="post" action="${href.discussion('forum', discussion.forum.id)}">
          <fieldset>

            <div class="field">
              <py:if test="req.authname == 'anonymous'">
                  <span>You are posting as anonymous, if you have an account we recommend that you <a href="${conf.url_home_path}/user">log in</a></span>
              </py:if>
              <input type="hidden" id="author" name="author" value="${req.authname}" />
            </div>

            <div class="field">
              <label for="subject" id="subject">Subject:</label>
              <input type="text" id="subjectbox" name="subject" value="${req.args.subject}"/><br/>
            </div>

              <py:choose>
                <py:when test="req.args.preview">
                    <div class="rounded_textarea">
                        <textarea id="add_msg_body" name="body"
                              class="wikitext" rows="20" cols="131">${req.args.body}</textarea>
                        <div class="corner topleft"></div>
                        <div class="corner topright"></div>
                        <div class="corner bottomleft"></div>
                        <div class="corner bottomright"></div>
                    </div>
                </py:when>
                <py:otherwise>
                    <div class="rounded_textarea">
                        <textarea id="add_msg_body" name="body"
                              class="wikitext" rows="20" cols="131"></textarea>
                        <div class="corner topleft"></div>
                        <div class="corner topright"></div>
                        <div class="corner bottomleft"></div>
                        <div class="corner bottomright"></div>
                    </div>
                </py:otherwise>
              </py:choose>

            <div py:if="discussion.moderator" class="field">


              <label for="subscribers">Subscribers:</label><br/>
              <py:choose>
                <select py:when="len(discussion.users) > 0 and 7 > len(discussion.users)" id="subscribers" name="subscribers" multiple="on">
                  <option py:for="user in discussion.users" value="${user}">${user}</option>
                </select>
                <select py:when="len(discussion.users) > 6" id="subscribers" name="subscribers" size="6" multiple="on">
                  <option py:for="user in discussion.users" value="${user}">${user}</option>
                </select>
              </py:choose><br/>
            </div>

            <div py:if="discussion.moderator" class="field">
              <label for="unregistered_subscribers">Unregistered subscribers
                (e-mails):</label>
              <br/>
              <input type="text" id="unregistered_subscribers"
                name="unregistered_subscribers">
                ${req.args.unregistered_subscribers}</input>
              <br/>
            </div>
            
            <div py:if="discussion.authemail" class="field">
              <label for="subscribe">
                <input py:if="req.args.subscribe" type="checkbox" id="subscribe"
                  name="subscribe" checked="yes" value="1"
                  onchange="subscription_select('${req.authname}',
                  this.checked);"/>
                <input py:if="not req.args.subscribe" type="checkbox"
                  id="subscribe" name="subscribe" value="0"
                  onchange="subscription_select('${req.authname}',
                  this.checked);"/>
                Subscribe to topic.
              </label><br/>
            </div>

            <div py:if="discussion.moderator" class="field">
              <label for="important">
                <input py:if="req.args.important" type="checkbox" id="important" name="important" checked="yes" value="1"/>
                <input py:if="not req.args.important" type="checkbox" id="important" name="important" value="1"/>
              Make this topic sticky at the top.
              </label><br/>
            </div>


            <py:choose>
                <py:when test="('DISCUSSION_MODERATE' in perm and discussion.moderator) or ((discussion.authname == discussion.topic.author) and (discussion.authname != 'anonymous'))">
                    <div class="subscribers" py:if="('DISCUSSION_MODERATE' in perm and discussion.moderator) or ((discussion.authname == discussion.topic.author) and (discussion.authname != 'anonymous'))">
                        <input type="hidden" id="subscribers" name="subscribers"></input><br/>
    	            </div>
    	       </py:when>
               <py:otherwise>
                    <input type="hidden" id="subscribers" name="subscribers"></input><br/>
               </py:otherwise>
            </py:choose>
            
            <div class="buttons">
				<span class="secondaryButton">
					<input type="submit" name="submit" value="Submit" style="width:120px;"/>
				</span> 
				<span class="secondaryButton">
					<input type="button" name="cancel" value="Cancel" onclick="location.href = '${href.discussion('forum', discussion.forum.id)}'"  style="width:120px;"/>
				</span> 
              <input type="hidden" name="discussion_action" value="post-add"/>
            </div>

          </fieldset>
        </form>

      </div>
    </div>

    <xi:include href="discussion-footer.html"/>
  </body>
</html>
